首页 > 试题广场 >

Excel列名称

[编程题]Excel列名称
  • 热度指数:1727 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解

excel列序号与列名称的映射关系是:
1->A
2->B
...
27->AA
28->AB
...

数据范围:
示例1

输入

5

输出

"E"
示例2

输入

29

输出

"AC"
class Solution:
    def ExcelTitle(self , n: int) -> str:
        # write code here
        import string
        res = ''
        while n:
            n -= 1
            res = string.ascii_uppercase[n%26] + res
            n //= 26
        return res

发表于 2022-07-03 17:02:27 回复(0)